/**
 * Created by jimmy on 17/3/24.
 */
import { Base } from '../../utils/base.js'

class My extends Base {
	constructor() {
		super();
	}


	//得到用户信息
	getUserInfo(cb) {
		var that = this;
		wx.login({
			success: function () {
				wx.getUserInfo({
					success: function (res) {
						typeof cb == "function" && cb(res.userInfo);
						that._updateUserInfo(res.userInfo);
					},
					fail: function (res) {
						typeof cb == "function" && cb({
							avatarUrl: '../../imgs/icon/user@default.png',
							nickName: '你好盐匠'
						});
					}
				});
			},
		})
	}

	getUser(callback){
		var param = {
			url:'/user/info',
			sCallback:function(data){
				callback&&callback(data);
			}
		};
		this.request(param);
	}


	/*更新用户信息到服务器*/
	_updateUserInfo(res) {
		var allParams = {
			url: 'user/wx_info',
			data: {extend: JSON.stringify(res) },
			type: 'post',
			sCallback: function (data) {
			}
		};
		this.request(allParams);

	}
}

export { My }